package com.baor.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baor.dao.*;
import com.baor.domain.*;
import com.baor.enums.FuncEnum;
import com.baor.service.LittleService;
import com.baor.utils.*;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.query.MPJQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.baor.utils.DateUtil.now;
import static com.google.common.hash.Hashing.md5;

@Service
public class LittleServiceImpl implements LittleService {

    @Autowired
    private MoneyDao moneyDao;

    @Autowired
    private VipDao userDao;

    @Autowired
    private DistributionRecordDao recordDao;

    @Autowired
    private GoodsDao goodsDao;

    @Autowired
    private AloneDao aloneDao;

    @Autowired
    private DistributionLevelDao levelDao;

    @Autowired
    private DistributorDao orDao;

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private InvoiceDao invoiceDao;

    @Autowired
    private CarDao carDao;

    @Value("${upload.file.location}")
    private String filePath;

    @Value("${getTwo.url}")
    private String url;



    @Override
    public AjaxResult<?> disCenter(Map<String, Object> map) {
        if ( map.get("userId") == null || "".equals(map.get("userId")) )
            return AjaxResult.error("userId is null",null);
        String userId = map.get("userId").toString();
        UserVo userVo = userDao.selectById(userId);
        Map<String,Object> res = new HashMap<>();
        MPJLambdaWrapper<MoneyVo> mpj = getMpj2(userId)
                .eq(MoneyVo::getSiteId, map.get("siteId"));
        if ( map.get("startTime") != null && ! "".equals(map.get("startTime")) )//>
            mpj.ge(MoneyVo::getCreateTime,map.get("startTime"));//ge >=
        if ( map.get("endTime") != null && ! "".equals(map.get("endTime")) )//<
            mpj.le(MoneyVo::getCreateTime,map.get("endTime"));//le <=
        if ( map.get("source") != null && ! "".equals(map.get("source")) )//<
            mpj.like(MoneyVo::getMoneySourceId,map.get("source"));//le <=
        List<MoneyVo> records = moneyDao.selectList(mpj);
        res.put("total_money",records.stream()
                .map(x -> x.getMoneyChange())
                .reduce(BigDecimal.ZERO,BigDecimal::add));//佣金总额
        res.put("not_money",records.stream().filter(x -> x.getMoneyStatus().equals("未提现"))
                .map(x -> x.getMoneyChange())
                .reduce(BigDecimal.ZERO,BigDecimal::add));//可提现
        res.put("in_money",records.stream().filter( x -> x.getMoneyStatus().equals("提现中"))
                .map(x -> x.getMoneyChange())
                .reduce(BigDecimal.ZERO,BigDecimal::add));//体现中
        res.put("had_money",records.stream().filter( x -> x.getMoneyStatus().equals("已提现"))
                .map(x -> x.getMoneyChange())
                .reduce(BigDecimal.ZERO,BigDecimal::add));//累计结算佣金 - 已提现
//        res.put("superior",userVo.getUserSuperior() != null ? userDao.selectById(userVo.getUserSuperior()) != null ? : null);
        UserVo userVo1 = null;
        if ( userVo.getUserSuperior() != null ){
            userVo1 = userDao.selectById(userVo.getUserSuperior());
        }
        res.put("superior",userVo1 != null ? userVo1.getUserTel() : null);
        res.put("userTel",userVo.getUserTel());
        res.put("userImage",userVo.getUserImage());
        res.put("sons",getSons(userId));
        res.put("teams",0);
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> details(Map<String, Object> map) {
        if ( map.get("userId") == null || "".equals(map.get("userId")) )
            return AjaxResult.error("userId is null",null);
        MPJLambdaWrapper<MoneyVo> mpj = getMpj3(map.get("userId").toString())
                .eq(MoneyVo::getSiteId, map.get("siteId"));
        if ( map.get("startTime") != null && ! "".equals(map.get("startTime")) )//>
            mpj.ge(MoneyVo::getCreateTime,map.get("startTime"));//ge >=
        if ( map.get("endTime") != null && ! "".equals(map.get("endTime")) )//<
            mpj.le(MoneyVo::getCreateTime,map.get("endTime"));//le <=
        if ( map.get("source") != null && ! "".equals(map.get("source")) )
            mpj.like(MoneyVo::getMoneySourceId,map.get("source"));
        if ( map.get("type") != null && ! "".equals(map.get("type")) )
            mpj.like(MoneyVo::getAccountType,map.get("type"));
        Page<MoneyVo> page = moneyDao.selectPage(getPage2(map), mpj);
        List<MoneyVo> records = page.getRecords();
        long pages = page.getPages();
        LambdaQueryWrapper<UserVo> select = new LambdaQueryWrapper<UserVo>()
                .select(UserVo::getUserId)
                .eq(UserVo::getUserId,map.get("userId"))
                .select(UserVo.class,x -> x.getColumn().equals("user_canuse_money")
                        || x.getColumn().equals("user_can_be")
                        || x.getColumn().equals("user_cant_be"))
                .eq(UserVo::getSiteId,map.get("siteId"));
        if ( map.get("userId") != null && ! "".equals(map.get("userId")) )
            select.like(UserVo::getUserId,map.get("userId"));
        List<UserVo> list = userDao.selectList(select);
        //-------- 数据封装 --------
        Map<String,Object> res = new HashMap<>();
        res.put("pageCount",pages);
        res.put("list",records);
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> disOrder(Map<String, Object> map) {
        if ( map.get("userId") == null || "".equals(map.get("userId")) )
            return AjaxResult.error("userId is null",null);
        MPJLambdaWrapper<DistributionRecordVo> mpj = getMpj(map.get("userId").toString())
                .eq(DistributionRecordVo::getSiteId,map.get("siteId"));
        if ( map.get("status") != null && !"".equals(map.get("status")) )
            mpj.eq(DistributionRecordVo::getDistributionStatus,map.get("status"));
        if ( map.get("startTime") != null && ! "".equals(map.get("startTime")) )//>
            mpj.ge(DistributionRecordVo::getCreateTime,map.get("startTime"));//ge >=
        if ( map.get("endTime") != null && ! "".equals(map.get("endTime")) )//<
            mpj.le(DistributionRecordVo::getCreateTime,map.get("endTime"));//le <=
        if ( map.get("userId") != null && !"".equals(map.get("userId")) ){
            mpj.eq(DistributionRecordVo::getUserId,map.get("userId"));
        }
        if ( map.get("distributionStatus") != null && !"".equals(map.get("distributionStatus")) ){
            mpj.eq(DistributionRecordVo::getDistributionStatus,map.get("distributionStatus"));
        }
        Page<DistributionRecordVo> page = recordDao.selectPage(getPage(map),mpj);
        //-------- 结果处理 --------
        List<DistributionRecordVo> records = page.getRecords();
//        records.stream().
        long pages = page.getPages();
        //-------- 数据封装 --------
        Map<String,Object> res = new HashMap<>();
        res.put("pageCount",pages);
        res.put("list",records);
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> disGoods(Map<String, Object> map) {
        if ( map.get("userId") == null || "".equals(map.get("userId")) )
            return AjaxResult.error("userId is null",null);
        Page<GoodsVo> page = goodsDao.selectPage(getPage3(map), getMpj());
        List<GoodsVo> records = page.getRecords();
        records.forEach(x -> {
            x.setGoodsShare(getShare(x,map.get("userId").toString()));
        });
        long pages = page.getPages();
        Map<String,Object> res = new HashMap<>();
        res.put("pageCount",pages);
        res.put("list",records);
        return AjaxResult.success(res);
    }

    private BigDecimal getShare(GoodsVo vo,String userId){
        DistributorVo or = orDao.selectOne(new LambdaQueryWrapper<DistributorVo>().eq(DistributorVo::getUserId, userId));
        BigDecimal firstLevel1 = null;
        //默认分佣规则
        BigDecimal num = new BigDecimal(1);//购买数量
        BigDecimal priceValue = vo.getPriceValue();//商品价格
        BigDecimal orderSubtract = BigDecimal.ZERO;//优惠劵金额
        BigDecimal multiply = num.multiply(priceValue);//数量 x 价格
        BigDecimal total = multiply.subtract(orderSubtract);//总价 - 优惠劵
        total = total.divide(new BigDecimal(100));//百分比
        //商品若存在单独规则
        if ( vo.getDefaultDistribution().equals("默认规则") ){//默认分销规则
            DistributionLevelVo distributionLevelVo = levelDao.selectOne(new LambdaQueryWrapper<DistributionLevelVo>()
                    .eq(DistributionLevelVo::getDistributionLevelId, or.getDistributionLevelId()));
            firstLevel1 = distributionLevelVo.getFirstLevel();
        } else {
            List<AloneVo> aloneVos = aloneDao.selectList(new LambdaQueryWrapper<AloneVo>()
                    .eq(AloneVo::getGoodsId, vo.getGoodsId()));
            if ( aloneVos.size() == 1 && aloneVos.get(0).getAloneMoney().compareTo(BigDecimal.ZERO) > 0 ){
                /**
                 * 固定金额
                 */
                BigDecimal aloneMoney = aloneVos.get(0).getAloneMoney();
                return aloneMoney;
            }
            for ( AloneVo x : aloneVos ){
                if ( x.getDistributionLevelId().equals(or.getDistributionLevelId()) )
                    firstLevel1 = x.getFirstLevel();
            }
        }
        BigDecimal multiply1 = firstLevel1.multiply(total);
        return multiply1;
    }

    private Page<GoodsVo> getPage3(Map<String,Object> map){
        if ( map.get("pageIndex") == null || "".equals(map.get("pageIndex")) )
            map.put("pageIndex",1);
        if ( map.get("pageSize") == null || "".equals(map.get("pageSize")) )
            map.put("pageSize",10);
        Long pageIndex = Long.valueOf(map.get("pageIndex").toString());
        Long pageSize = Long.valueOf(map.get("pageSize").toString());
        return new Page<GoodsVo>(pageIndex,pageSize);
    }

    private MPJLambdaWrapper<GoodsVo> getMpj(){
        MPJLambdaWrapper<GoodsVo> mpj = new MPJLambdaWrapper<>();
        mpj
                .selectAll(GoodsVo.class)//不需要第二行的话,第一行一同删除,用这行代替
                .selectFunc(FuncEnum.IF_VIRTUAL,GoodsVo::getGoodsVirtual)//自定义枚举类FuncEnum,(as),主表字段
                .selectFunc(FuncEnum.IF_SELL,GoodsVo::getGoodsSell)
                .selectFunc(FuncEnum.IF_TRUE,GoodsVo::getGoodsDistribution)
                .selectFunc(FuncEnum.IF_DEFAULT,GoodsVo::getDefaultDistribution)
                .eq(GoodsVo::getGoodsDistribution,1);
        return mpj;
    }


    private MPJLambdaWrapper<DistributionRecordVo> getMpj(String userId){
        MPJLambdaWrapper<DistributionRecordVo> mpj = new MPJLambdaWrapper<>();
        mpj
                .selectAll(DistributionRecordVo.class)//不需要第二行的话,第一行一同删除,用这行代替
                .eq(MoneyVo::getUserId,userId)
                .selectAs(UserVo::getUserName, OrderVo::getUserId)
                .leftJoin(UserVo.class,UserVo::getUserId,DistributionRecordVo::getUserId)
                .selectAs(GoodsVo::getGoodsName,DistributionRecordVo::getGoodsId)
                .selectAs(GoodsVo::getGoodsImage,DistributionRecordVo::getGoodsImage)
                .leftJoin(GoodsVo.class,GoodsVo::getGoodsId,DistributionRecordVo::getGoodsId)
                .selectFunc(FuncEnum.IF_LEVEL,DistributionRecordVo::getDistributionLevel)
                .selectFunc(FuncEnum.IF_DISSTATUS,DistributionRecordVo::getDistributionStatus);
        return mpj;
    }
    private MPJLambdaWrapper<MoneyVo> getMpj3(String userId){
        MPJLambdaWrapper<MoneyVo> mpj =
                new MPJLambdaWrapper<MoneyVo>()
                        .selectAll(MoneyVo.class)
                        .eq(MoneyVo::getUserId,userId)
                        .selectAs(UserVo::getUserAccount,MoneyVo::getUserAccount)
                        .selectAs(UserVo::getUserImage,MoneyVo::getUserImage)
                        .leftJoin(UserVo.class,UserVo::getUserId,MoneyVo::getUserId)
                        .selectFunc(FuncEnum.CASE_MS,MoneyVo::getMoneyStatus);
        return mpj;
    }

    private Page<DistributionRecordVo> getPage(Map<String,Object> map){
        if ( map.get("pageIndex") == null || "".equals(map.get("pageIndex")) )
            map.put("pageIndex",1);
        if ( map.get("pageSize") == null || "".equals(map.get("pageSize")) )
            map.put("pageSize",10);
        Long pageIndex = Long.valueOf(map.get("pageIndex").toString());
        Long pageSize = Long.valueOf(map.get("pageSize").toString());
        return new Page<>(pageIndex,pageSize);
    }

    private Page<MoneyVo> getPage2(Map<String,Object> map){
        if ( map.get("pageIndex") == null || "".equals(map.get("pageIndex")) )
            map.put("pageIndex",1);
        if ( map.get("pageSize") == null || "".equals(map.get("pageSize")) )
            map.put("pageSize",10);
        Long pageIndex = Long.valueOf(map.get("pageIndex").toString());
        Long pageSize = Long.valueOf(map.get("pageSize").toString());
        return new Page<>(pageIndex,pageSize);
    }

    private Integer getSons(String userId) {
        Integer num = 0;
        List<UserVo> list = userDao.selectList(null);
        List<UserVo> collect = list.stream()
                .filter(x -> x.getUserSuperior().equals(userId)).collect(Collectors.toList());
        num += collect.size();
        for ( UserVo x : collect )
            num += list.stream()
                    .filter(y -> Integer.valueOf(y.getUserSuperior()).equals(x.getUserId()))
                    .collect(Collectors.toList()).size();
        return num;
    }

    private MPJLambdaWrapper<MoneyVo> getMpj2(String userId){
        MPJLambdaWrapper<MoneyVo> mpj =
                new MPJLambdaWrapper<MoneyVo>()
                        .selectAll(MoneyVo.class)
                        .eq(MoneyVo::getUserId,userId)
                        .selectAs(UserVo::getUserAccount,MoneyVo::getUserAccount)
                        .selectAs(UserVo::getUserImage,MoneyVo::getUserImage)
                        .leftJoin(UserVo.class,UserVo::getUserId,MoneyVo::getUserId)
                        .selectFunc(FuncEnum.CASE_MS,MoneyVo::getMoneyStatus);
        return mpj;
    }

    /**
     * map{
     *     order_goods_num 购买数量
     *     price_value 货物单价
     * }
     * @param list
     * @return
     */

    @Override
    public AjaxResult<?> shopCar(List<OrderVo> list) {
        BigDecimal zero = BigDecimal.ZERO;
        for ( OrderVo orderVo : list ){
            Long orderGoodsNum = orderVo.getOrderGoodsNum();
            BigDecimal priceValue = orderVo.getPriceValue();
            BigDecimal bigDecimal = new BigDecimal(orderGoodsNum);
            BigDecimal subtract = priceValue.multiply(bigDecimal);
            zero = zero.add(subtract);
        }
        return AjaxResult.success(zero);
    }

    @Override
    public AjaxResult<?> shoping(List<OrderVo> list) {
        BigDecimal zero = BigDecimal.ZERO;
        for ( OrderVo orderVo : list ){
            Long orderGoodsNum = orderVo.getOrderGoodsNum();
            orderVo.setPriceValue(goodsDao.selectById(orderVo.getGoodsId()).getPriceValue());
            BigDecimal priceValue = orderVo.getPriceValue();
            BigDecimal bigDecimal = new BigDecimal(orderGoodsNum);
            BigDecimal subtract = priceValue.multiply(bigDecimal);
            zero = zero.add(subtract);
        }
        String time = now();
        String coding = getCode();
        for ( OrderVo x : list ){
            x.setOrderCode(coding);
            x.setCreateTime(time);
//            if ( !Optional.of(x.getOrderMessage()).isPresent() )
            if ( x.getOrderMessage() == null || "".equals(x.getOrderMessage()) )
                x.setOrderMessage("无");
//            if ( !Optional.of(x.getOrderNotes()).isPresent() )
            if ( x.getOrderNotes() == null || "".equals(x.getOrderNotes()) )
                x.setOrderNotes("无");
//            if ( !Optional.of(x.getOrderSubtract()).isPresent() )
            if ( x.getOrderSubtract() == null || "".equals(x.getOrderSubtract()) )
                x.setOrderSubtract(BigDecimal.ZERO);
//            if ( !Optional.of(x.getOrderDeliveryAmount()).isPresent() )
            if ( x.getOrderDeliveryAmount() == null || "".equals(x.getOrderDeliveryAmount()) )
                x.setOrderDeliveryAmount(BigDecimal.ZERO);
            x.setOrderRealAmount(
                    new BigDecimal(x.getOrderGoodsNum())
                            .multiply(x.getPriceValue())
                            .subtract(x.getOrderDeliveryAmount())
                            .subtract(x.getOrderSubtract())
            );
            x.setOrderStatusId("3");
            x.setOrderDeliveryId("1");
            x.setOrderSourceId("1");
            x.setGoodsInvoice("0");
            orderDao.insert(x);
        }
        InvoiceVo invoiceVo = new InvoiceVo();
        try{
            OrderVo one = list.get(0);
            invoiceVo.setInvoiceName(getInvoice());
            StringBuilder sBuilder = new StringBuilder();
            StringBuilder sBuilder2 = new StringBuilder();
            BigDecimal zero1 = BigDecimal.ZERO;
            for ( OrderVo two : list ){
                sBuilder.append(getContent(two))
                        .append(",");
                zero1 = zero1.add(two.getOrderRealAmount());
                sBuilder2.append(two.getOrderId())
                        .append(",");
            }
            invoiceVo.setInvoiceContent(sBuilder.substring(0,sBuilder.length() - 1).toString());
            invoiceVo.setInvoiceIdentification(one.getUserId());
            invoiceVo.setInvoicePrice(zero1);
            invoiceVo.setCreateTime(now());
            invoiceVo.setStartTime(now());
            invoiceVo.setInvoiceTypeId("0");
            invoiceVo.setInvoiceStatus("0");
            invoiceVo.setOrderId(sBuilder2.substring(0,sBuilder2.length() - 1).toString());
            invoiceVo.setUserId(one.getUserId());
            invoiceVo.setSiteId(one.getSiteId());
            invoiceDao.insert(invoiceVo);
            int delete = carDao.delete(new QueryWrapper<CarVo>()
                    .eq("site_id", list.get(0).getSiteId())
                    .eq("user_id", list.get(0).getUserId())
                    .in("goods_id", list.stream()
                            .map(x -> x.getGoodsId())
                            .collect(Collectors.toList())
                            .toArray()));
//            System.out.println(delete);
        } catch ( Exception ex ){
            ex.printStackTrace();
            return AjaxResult.error("什么也不买就别在这里给我点点点点点点的(goodsId is null or invalid,else call me)",null);
        }
        return AjaxResult.success(invoiceVo);
    }

    private String s(Object ...obj){
        System.out.println(obj);
        return null;
    }

    @Override
    public AjaxResult<?> addCar(CarVo carVo) {
        int size = carDao.selectList(new LambdaQueryWrapper<CarVo>()
                .eq(CarVo::getGoodsId, carVo.getGoodsId())
                .eq(CarVo::getUserId, carVo.getUserId())).size();
        if ( size > 0 )
            return AjaxResult.error("亲亲，您已经第二次将该物品添加到购物车了，看来您是非常喜欢本物品，赶紧来购物车带它回家吧qwq");
        carVo.setCreateTime(now());
        carVo.setNum(1);
        carDao.insert(carVo);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult<?> carList(CarVo carVo) {
        if ( carVo.getUserId() == null || "".equals(carVo.getUserId()) )
            return AjaxResult.error("请问你是:");
        if ( carVo.getSiteId() == null || "".equals(carVo.getSiteId()) )
            return AjaxResult.error("请问你来自:");
        List<CarVo> carVos = carDao.selectList(new MPJQueryWrapper<CarVo>()
                .selectAll(CarVo.class)
                .select("(select b.goods_name from t_goods b where b.goods_id = t.goods_id) as goods_name")
                .select("(select b.price_value from t_goods b where b.goods_id = t.goods_id) as price_value")
                .select("(select b.goods_image from t_goods b where b.goods_id = t.goods_id) as goods_image")
                .eq("user_id",carVo.getUserId())
                .eq("site_id",carVo.getSiteId())
                .orderByDesc("create_time"));
//        new MPJLambdaWrapper<CarVo>().or
        return AjaxResult.success(carVos);
    }

    @Override
    public AjaxResult<?> getTwo(UserVo userVo) {
        String userId = userVo.getUserId().toString();
        if ( userId == null || "".equals(userId) )
            return AjaxResult.error("userId is null");
        // https://www.hotspotin.top/mall/api/pay/two/
        // https://www.hotspotin.top/api-app/2
        String codeToFile = MyQrCodeUtil.createCodeToFile(url + userId + "/",
                new File(filePath + "/api"),
                getRandom(userId) + ".jpg");
        return AjaxResult.success(codeToFile);
    }

    @Override
    public AjaxResult<?> createCar(Map<String, Object> map) {
        return null;
    }

    @Override
    public AjaxResult<?> desCar(Map<String, Object> map) {
        return null;
    }

    @Override
    public AjaxResult<?> updateCar(List<CarVo> list) {
        for ( CarVo carVo : list )
            if ( carVo.getNum().compareTo(0) > 0 )
                carDao.updateById(carVo);
            else if ( carVo.getNum().compareTo(0) == 0 )
                carDao.deleteById(carVo.getCarId());
            else
                return AjaxResult.error("要长脑子了(O.o)");
        return AjaxResult.success();
    }

    @Override
    public AjaxResult<?> deleteCar(List<CarVo> list) {
        for ( CarVo carVo : list )
            carDao.deleteById(carVo.getCarId());
        return AjaxResult.success();
    }

    @Override
    public AjaxResult<?> test() {
        return AjaxResult.success(orderDao.insertOrderVo(new OrderVo()));
    }
//
//    public AjaxResult<?> enroll(UserVo userVo) {
//        //账号
//        List<UserVo> vo = this.vipDao.check(userVo.getUserTel());
//        if(vo == null || vo.isEmpty() || vo.equals("")){
//            String account = generateAccount(10);
//            userVo.setUserAccount(account);
//            //用户名
//            if(userVo.getUserName() == null || userVo.getUserName().equals("")){
//                userVo.setUserName("新用户"+generateAccount(4));
//            }
//            //加密
//            String pwd = MD5Utils.md5(userVo.getUserPassword());
//            userVo.setUserPassword(pwd);
//            //注册时间
//            LocalDateTime now = LocalDateTime.now();
//            userVo.setCreateTime(String.valueOf(now));
//            //注册来源
//            userVo.setOrderSourceId(String.valueOf(1));
//            int row = this.vipDao.insert(userVo);
//            this.appletService.registIf(userVo.getUserId());
//            if(row > 0){
//                return AjaxResult.success();
//            }else{
//                return AjaxResult.error();
//            }
//        }else{
//            return AjaxResult.error("该手机号已经注册");
//        }
//
//    }
//
//    public AjaxResult<?> addGrantUser(AuthorizationUtil authorizationUtil) {
//        Map<String,Object> map = new HashMap<>();
//        String params = "appid="+appid+"&secret="+wxsecret+"&js_code="+authorizationUtil.getCode()+"&grant_type=authorization_code";
//        String str = HttpRequestUtil.sendGet("https://api.weixin.qq.com/sns/jscode2session",params);
//        JSONObject json = JSONObject.parseObject(str);
//        System.out.println(params);
//        int code = 0;
//        String openId = "";
//        if(json.get("errcode")!= null){
//            code = (int) json.get("errcode");
//            if(code == 0 ){
//                openId = (String) json.get("openid");
//                return AjaxResult.success(openId);
//            }else{
//                String str1 = "微信授权失败";
//                System.out.println(json);
//                return AjaxResult.error(str1);
//            }
//        }else{
//            openId = (String) json.get("openid");
//            return AjaxResult.success(openId);
//        }
//    }


    private String getRandom(String userId){
        return new StringBuilder()
                .append(System.currentTimeMillis())
                .append((int)(Math.random()*9999) + 1)
                .append(userId)
                .toString();
    }


    private String getCode(){
        return new StringBuilder()
                .append("LITTLE")
                .append(System.currentTimeMillis())
                .append((int)Math.random() * 999999 + 1)
                .toString();
    }

    private String getInvoice(){
        return new StringBuilder()
                .append("INVOICE")
                .append(System.currentTimeMillis())
                .append((int)Math.random() * 999999 + 1)
                .toString();
    }

    private String getContent(OrderVo one){
        GoodsVo goodsVo = goodsDao.selectById(one.getGoodsId());
        return new StringBuilder()
                .append(one.getOrderGoodsNum())
                .append(goodsVo.getGoodsUnit())
                .append(goodsVo.getGoodsName())
                .toString();
    }


}
